package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.SysProjectStepEntity;
import com.company.project.service.SysProjectStepService;



/**
 * 项目步骤表
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2022-03-04 10:33:02
 */
@Controller
@RequestMapping("/")
public class SysProjectStepController {
    @Autowired
    private SysProjectStepService sysProjectStepService;


    /**
    * 跳转到页面
    */
    @RequestMapping("/index/sysProjectStep/{projectId}")
    public String sysProjectStep(ModelMap model,@PathVariable  String projectId) {
        model.put("projectId",projectId);
        return "sysprojectstep/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("sysProjectStep/add")
    @RequiresPermissions("sysProjectStep:add")
    @ResponseBody
    public DataResult add(@RequestBody SysProjectStepEntity sysProjectStep){
        sysProjectStepService.save(sysProjectStep);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("sysProjectStep/delete")
    @RequiresPermissions("sysProjectStep:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        sysProjectStepService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("sysProjectStep/update")
    @RequiresPermissions("sysProjectStep:update")
    @ResponseBody
    public DataResult update(@RequestBody SysProjectStepEntity sysProjectStep){
        sysProjectStepService.updateById(sysProjectStep);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("sysProjectStep/listByPage")
    @RequiresPermissions("sysProjectStep:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SysProjectStepEntity sysProjectStep){
        LambdaQueryWrapper<SysProjectStepEntity> queryWrapper = Wrappers.lambdaQuery();
        //必须传入项目主键，否则无数据
        if(!StringUtils.isEmpty(sysProjectStep.getProjectId())){
            queryWrapper.like(SysProjectStepEntity::getProjectId, sysProjectStep.getProjectId());
        }else{
            queryWrapper.like(SysProjectStepEntity::getDeleted, "0");
        }
        //查询步骤名称
        if(!StringUtils.isEmpty(sysProjectStep.getStepName())){
            queryWrapper.like(SysProjectStepEntity::getStepName, sysProjectStep.getStepName());
        }
        queryWrapper.orderByAsc(SysProjectStepEntity::getOrderBy);
        List<SysProjectStepEntity> iPage = sysProjectStepService.list(queryWrapper);
        return DataResult.success(iPage);
    }

}
